﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace UserControlLib
{
    /// <summary>
    /// 加载效果窗体
    /// </summary>
    public partial class LoadIngWin : Window
    {
        public LoadIngWin()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 字体背景
        /// </summary>
        public static readonly DependencyProperty BorderBackgroundProperty =
            DependencyProperty.Register("BorderBackground", typeof(Brush), typeof(LoadIngWin), new PropertyMetadata(new SolidColorBrush(Colors.Gray)));
        /// <summary>
        /// 字体背景圆角
        /// </summary>
        public static readonly DependencyProperty BorderCornerRadiusProperty =
            DependencyProperty.Register("BorderCornerRadius", typeof(CornerRadius), typeof(LoadIngWin), new PropertyMetadata(new CornerRadius(3)));
        /// <summary>
        /// 字体背景宽
        /// </summary>
        public static readonly DependencyProperty BorderWidthProperty =
            DependencyProperty.Register("BorderWidth", typeof(double), typeof(LoadIngWin), new PropertyMetadata(55.0));
        /// <summary>
        /// 字体背景高
        /// </summary>
        public static readonly DependencyProperty BorderHeightProperty =
            DependencyProperty.Register("BorderHeight", typeof(double), typeof(LoadIngWin), new PropertyMetadata(25.0));
        /// <summary>
        /// 字体背景透明度
        /// </summary>
        public static readonly DependencyProperty BorderOpacityProperty =
            DependencyProperty.Register("BorderOpacity", typeof(double), typeof(LoadIngWin), new PropertyMetadata(0.9));

        /// <summary>
        /// 文本内容
        /// </summary>
        public static readonly DependencyProperty TextBlockTextProperty =
            DependencyProperty.Register("TextBlockText", typeof(string), typeof(LoadIngWin), new PropertyMetadata("加载中..."));
        /// <summary>
        /// 字体颜色
        /// </summary>
        public static readonly DependencyProperty TextBlockForegroundProperty =
            DependencyProperty.Register("TextBlockForeground", typeof(Brush), typeof(LoadIngWin), new PropertyMetadata(Brushes.Red));
        /// <summary>
        /// 字体大小
        /// </summary>
        public static readonly DependencyProperty TextBlockFontSizeProperty =
            DependencyProperty.Register("TextBlockFontSize", typeof(double), typeof(LoadIngWin), new PropertyMetadata(12.0));

        // 属性访问器
        public Brush BorderBackground
        {
            get => (Brush)GetValue(BorderBackgroundProperty);
            set => SetValue(BorderBackgroundProperty, value);
        }

        public CornerRadius BorderCornerRadius
        {
            get => (CornerRadius)GetValue(BorderCornerRadiusProperty);
            set => SetValue(BorderCornerRadiusProperty, value);
        }

        public double BorderWidth
        {
            get => (double)GetValue(BorderWidthProperty);
            set => SetValue(BorderWidthProperty, value);
        }

        public double BorderHeight
        {
            get => (double)GetValue(BorderHeightProperty);
            set => SetValue(BorderHeightProperty, value);
        }

        public double BorderOpacity
        {
            get => (double)GetValue(BorderOpacityProperty);
            set => SetValue(BorderOpacityProperty, value);
        }

        public string TextBlockText
        {
            get => (string)GetValue(TextBlockTextProperty);
            set => SetValue(TextBlockTextProperty, value);
        }

        public Brush TextBlockForeground
        {
            get => (Brush)GetValue(TextBlockForegroundProperty);
            set => SetValue(TextBlockForegroundProperty, value);
        }

        public double TextBlockFontSize
        {
            get => (double)GetValue(TextBlockFontSizeProperty);
            set => SetValue(TextBlockFontSizeProperty, value);
        }


        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // 确保动画启动
            var storyboard = this.FindResource("rotationStoryboard") as Storyboard;
            if (storyboard != null)
            {
                storyboard.Begin(this);
            }
        }

        private void Window_UnLoaded(object sender, RoutedEventArgs e)
        {
            // 确保动画停止
            var storyboard = this.FindResource("rotationStoryboard") as Storyboard;
            if (storyboard != null)
            {
                storyboard.Stop(this);
            }
            this.Close();
        }
    }
}
